<template>
  <div class="drugsQuery-conatiner">
    <div class="playImte-header">
      <span class="title">价格列表</span>
      <div class="search-group">
        <el-input v-model.trim="kewWord" placeholder="请输入关键词"></el-input>
        <el-button type="success" style="margin-left:10px;"  @click="searchMethod">搜索</el-button>
        <el-button @click="restMethod">重置</el-button>
      </div>
    </div>
    <div class="playImte-table">
      <table v-if="currentlList.length >0">
        <tr>
          <td style="width:20%;">
            <div class="table-title">商品名</div>
          </td>
          <td style="width:15%;">
            <div class="table-title">剂型</div>
          </td>
          <td style="width:15%;">
            <div class="table-title">规格</div>
          </td>
          <td style="width:15%;">
            <div class="table-title">计价单位</div>
          </td>
          <td style="width:15%;">
            <div class="table-title">单价</div>
          </td>
          <td style="width:20%;">
            <div class="table-title">生产企业</div>
          </td>
        </tr>
        <tr v-for="(item,index) in currentlList" :key="index">
          <td>
            <div class="table-info">{{item.xmmc}}</div> 
          </td>
          <td>
            <div class="table-info">{{item.jx}}</div>
          </td>
          <td>
            <div class="table-info">{{item.gg}}</div>
          </td>
          <td>
            <div class="table-info">{{item.dw}}</div>
          </td>
          <td>
            <div class="table-info">¥{{item.jg}} 元</div>
          </td>
          <td>
            <div class="table-info">{{item.ypsccj}}</div>
          </td>
        </tr>
      </table>
      <empty v-if="currentlList.length == 0" />
    </div>
    <div class="playImte-button-group">
      <el-pagination :current-page.sync="currentPage" :page-size.sync="pageSize" @current-change="pageNext" background layout="prev, pager, next" :total="total">
      </el-pagination>
    </div>
    <v-back></v-back>
    <go-home></go-home>
    <div class="back-home-times">{{backTime}}S</div>
  </div>
</template>
    
    <script>
import vBack from '@/components/mainHeader/Back.vue';
import goHome from '@/components/mainHeader/GoHome.vue';
import { mapState } from 'vuex';
export default {
  components: { vBack, goHome },
  computed: {
    ...mapState({
      grid: (state) => state.app.UserGrid,
    }),
  },
  data() {
    return {
      pendingList: [],
      playTotal: 0,
      total: 0,
      pageSize:10,
      currentPage:1,
      isPalySuccess: false,
      modelShow: false,
      loading: false,
      countdown: 15,
      editVisible: false,
      detailList: [],
      currentlList: [],
      searchList: [],
      kewWord:'',
      backTime:60
    };
  },
  created() {
    this.initMethod();
    this.goBackHome();
  },
  methods: {
    initMethod() {
      this.$http.get(this.$API.GET_DRUGS).then((res) => {
        console.log('已缴费', res);
        if (res.code == 200) {
            this.pendingList = Array.isArray(res.data) ? res.data : [];
            this.pageNextPages(this.pendingList);
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    searchMethod(){
      if(this.kewWord){
        this.currentPage=1;
        let arr=[];
        this.pendingList.forEach(item=>{
          if(item.xmmc && item.xmmc.indexOf(this.kewWord)!=-1){
            arr.push(item)
          }
        })
        this.searchList=arr;
        this.pageNextPages(arr)
      }
    },
    restMethod(){
      this.kewWord='';
      this.currentPage=1;
      this.searchList=[];
      this.pageNextPages(this.pendingList);
    },
    pageNext(e){
      this.currentPage=e;
      this.pageNextPages((this.searchList.length>0?this.searchList:this.pendingList))
    },
    pageNextPages(list){
      this.total=Math.ceil(list.length/this.pageSize)
        let arr=[];
        for(let i=0;i<list.length;i++){
            if(i>=((this.currentPage-1)*this.pageSize) && i<(this.currentPage*this.pageSize)){
                arr.push(list[i]);
            }
        }
        this.currentlList=arr;
    },
    goBackHome(){
      this.backTime=60;
      clearInterval(this.timerHome);
      this.timerHome=setInterval(()=>{
        if(this.backTime == 1){
          clearInterval(this.timerHome);
          this.$router.replace('/');
        }
        this.backTime--
      },1000)
    }
  },
  destroyed() {
    clearInterval(this.timerHome);
  },
};
  </script>
    
    <style lang="less">
.drugsQuery-conatiner {
  width: 100%;
  height: 100%;
  .playImte-header {
    height: 8%;
    background: linear-gradient(to bottom, #4a8ad0, #75a3d1);
    display: flex;
    align-items: center;
    justify-content: space-around;
    .search-group{
      display: flex;
      align-items: center;
      width: 55%;
      .el-input--medium .el-input__inner{
        height: 76* @hv;
        line-height: 76px* @hv;
        font-size: 30 * @hv;
      }
      .el-button--medium {
        padding: 20* @hv 30* @wv;
        font-size: 30 * @hv;
    }
    }
    .title {
      font-size: 40 * @hv;
      color: #fff;
    }
  }
  table {
    border-collapse: collapse;
  }
  table,
  th,
  td {
    border: 1px solid #888;
  }
  .playImte-table {
    display: flex;
    justify-content: center;
    padding-top: 30 * @hv;
    height: 75vh;
    align-items: flex-start;
    table {
      width: 90%;
    }
    .table-title {
      padding: 20 * @hv 15 * @wv;
      font-size: 28 * @hv;
      color: #333;
      text-align: center;
      font-weight: bold;
    }
    .table-info {
      padding: 20 * @hv 15 * @wv;
      font-size: 28 * @hv;
      color: #555;
    }
  }
  .playImte-button-group {
    display: flex;
    padding-top: 30 * @hv;
    .playImte-button {
      width: 60%;
      height: 120 * @hv;
      font-size: 38 * @hv;
      background: #4a8ad0;
      color: #fff;
      text-align: center;
      line-height: 120 * @hv;
      border-radius: 120 * @hv;
    }
  }
  .table-title1 {
    padding: 20 * @hv 15 * @wv;
    font-size: 28 * @hv;
    color: #333;
    text-align: right;
    font-weight: bold;
  }
  .table-info1 {
    padding: 20 * @hv 15 * @wv;
    font-size: 28 * @hv;
    color: #555;
  }
  .el-pager li{
    width: 50*@wv!important;
    height: 60* @hv!important;
    line-height: 60* @hv!important;
    font-size: 30* @hv!important;
  }
  .btn-next,.btn-prev{
    width: 50*@wv!important;
    height: 60* @hv!important;
    line-height: 60* @hv!important;
    .el-icon{
        font-size: 30* @hv!important;
    }
  }
}
</style>
    